<%-- 
    Document   : lis
    Created on : 12-dec-2009, 1:00:31
    Author     : Simon
--%>

<%@include file="../header.jsp" %>

<h1>Consultations</h1>

<c:if test="${! empty flash}">
    <div class="flash notice">${flash}</div>
</c:if>


<form action="" onsubmit="return false;" id="search_patient" class="search">
    <input type="text" id="query" name="query" size="50" value="${query}"/>
</form>
<h2>Today</h2>

<table id="today" class="data">
    <thead>
        <tr>
            <td>Patient</td>
            <td>Date</td>
        </tr>
    </thead>
    <tbody>
        <c:forEach var="consultation" items="${consultations}" varStatus="status">
            <fmt:formatDate var="day" value="${consultation.date}" pattern="D" />
            <fmt:formatDate var="day_n" value="<%= new java.util.Date() %>" pattern="D" />
            <c:if test="${day - day_n == 0}">
                <tr>
                    <td class="patient_name">
                        <a href="${pageContext.request.contextPath}/gp/patient/select?id=${consultation.patientId}">${patients[status.count - 1]}</a>
                    </td>
                    <td>
                        <fmt:formatDate value="${consultation.date}" pattern="d MMM yyyy HH:mm" />
                    </td>
                </tr>
            </c:if>
        </c:forEach>
    </tbody>
</table>

<h2>Later</h2>

<table class="data">
    <thead>
        <tr>
            <td>Patient</td>
            <td>Date</td>
        </tr>
    </thead>
    <tbody>
        <c:forEach var="consultation" items="${consultations}" varStatus="status">
            <fmt:formatDate var="day" value="${consultation.date}" pattern="D" />
            <fmt:formatDate var="day_n" value="<%= new java.util.Date() %>" pattern="D" />
            <c:if test="${day - day_n > 0}">
                <tr>
                    <td class="patient_name">
                        <a href="${pageContext.request.contextPath}/gp/patient/select?id=${consultation.patientId}">${patients[status.count - 1]}</a>
                    </td>
                    <td>
                        <fmt:formatDate value="${consultation.date}" pattern="d MMM yyyy HH:mm" />
                    </td>
                </tr>
            </c:if>
        </c:forEach>
    </tbody>
</table>

<script type="text/javascript">
    $(document).ready(function(){
        var search_text = "Type to search a patient";
        var input = $("#search_patient #query");
        init_input_field(input, search_text, "#888");

        var size = 1 - $("#today th").size();
        if ($("#today tr").size() == size) {
            $("#today").hide();
            $("#today").before("No consultations.");
        }

        var display_row = $("td.patient_name").parent().css("display");
        if (!display_row)
            display_row = "table-row";
        input.keyup(function() {
            if (input.val() == search_text || input.val() == "") {
                jQuery.each($("td.patient_name"), function(index, item) {
                    $(item).parent().css("display",display_row);
                });
            };
            jQuery.each($("td.patient_name"), function(index, item) {
                if ($(item).text().toLowerCase().match(new RegExp(input.val().toLowerCase())))
                    $(item).parent().css("display",display_row);
                else
                    $(item).parent().css("display","none");
            });
        });

    });
</script>

<%@include file="../footer.jsp" %>
